// File Name: ws2812b_ctrl.h
// Author: kukukukuku~
// Date: 2024-06-26

#ifndef __WS2812B_CTRL_H
#define __WS2812B_CTRL_H

#include "at32f421.h"

#define WS2812B_GPIO_CRM                CRM_GPIOA_PERIPH_CLOCK
#define WS2812B_GPIO_PORT               GPIOA
#define WS2812B_GPIO_PIN                GPIO_PINS_7
#define WS2812B_GPIO_MUX_SOURCE         GPIO_PINS_SOURCE7
#define WS2812B_GPIO_MUX                GPIO_MUX_0

#define WS2812B_SPI_CRM                 CRM_SPI1_PERIPH_CLOCK
#define WS2812B_SPI                     SPI1

#define WS2812B_HIGH                    (0xFC)
#define WS2812B_LOW                     (0xC0)
#define WS2812B_RESET                   (0x00)

#define WS2812B_NUM                     (8)

#define WS2812B_RGB_VAL_MIN             (0)
#define WS2812B_RGB_VAL_MAX             (255)

#define WS2812B_MODE_FOLLOW_STEP_MOTOR  (0)
#define WS2812B_MODE_FOLLOW_PICKER      (1)

//WS2812B对象
typedef struct WS2812B
{
    uint8_t bData;
    uint8_t gData;
    uint8_t rData;
}WS2812B, *pWS2812B;

//WS2812B颜色数据联合体
typedef union WS2812B_RGB
{
    WS2812B ws2812b;
    uint32_t ws2812bRgb;
}WS2812B_RGB, *pWS2812B_RGB;

extern WS2812B_RGB ws2812b[WS2812B_NUM];   //WS2812B对象

extern uint8_t ws2812bMode;        //WS2812B模式

extern uint8_t ws2812bState;       //WS2812B状态
extern uint8_t ws2812bMode;        //WS2812B模式
extern uint8_t ws2812bCwMode;      //WS2812B正转时的RGB模式
extern uint8_t ws2812bCcwMode;     //WS2812B反转时的RGB模式

extern uint8_t ws2812bStopRed;     //WS2812B停止时红色值
extern uint8_t ws2812bStopGreen;   //WS2812B停止时绿色值
extern uint8_t ws2812bStopBlue;    //WS2812B停止时蓝色值

extern uint8_t ws2812bCwRed;       //WS2812B正转时红色值
extern uint8_t ws2812bCwGreen;     //WS2812B正转时绿色值
extern uint8_t ws2812bCwBlue;      //WS2812B正转时蓝色值

extern uint8_t ws2812bCcwRed;      //WS2812B反转时红色值
extern uint8_t ws2812bCcwGreen;    //WS2812B反转时绿色值
extern uint8_t ws2812bCcwBlue;     //WS2812B反转时蓝色值

//WS2812B配置
void ws2812b_config(void);

#endif //__WS2812B_CTRL_H
